package aishua.com.mytestapplist.diyiview;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import aishua.com.mytestapplist.utils.LogUtils;

/**
 * Created by aishua on 2017/4/12.
 */

public class MyLineLayout extends LinearLayout {
    private static final String TAG = "MyLineLayout-";
    public MyLineLayout(Context context) {
        super(context);
    }

    public MyLineLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        LogUtils.v(TAG+"MyLineLayout()");


    }

    public MyLineLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
//        setMeasuredDimension(600,600);
//        setBackgroundColor(Color.RED);

//        measureChild(getChildAt(0),300,300);
//         int widht=   MeasureSpec.makeMeasureSpec(300,MeasureSpec.AT_MOST);
//        int hegiht = MeasureSpec.makeMeasureSpec(200,MeasureSpec.AT_MOST);
//           getChildAt(0).measure(widht,hegiht);
        LogUtils.v(TAG+"onMeasure()");
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {

        super.onLayout(changed, l, t, r, b);
//       int count =  getChildCount();
//       View view = getChildAt(0);
//        view.layout(0,0,100,100);

        LogUtils.v(TAG+"onLayout()");
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {

        int e = event.getAction();
        switch (e) {
            case MotionEvent.ACTION_DOWN:
                LogUtils.v(TAG + "onTouchEvent()--MotionEvent.ACTION_DOWN");
//                return  false;
                break;
            case MotionEvent.ACTION_MOVE:
                LogUtils.v(TAG + "onTouchEvent()--MotionEvent.ACTION_MOVE");
//                return false;
                break;
            case MotionEvent.ACTION_UP:
                LogUtils.v(TAG + "onTouchEvent()--MotionEvent.ACTION_UP");
                break;
//                return true;
        }
        return super.onTouchEvent(event);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {

        int e = ev.getAction();
        switch (e) {
            case MotionEvent.ACTION_DOWN:
                LogUtils.v(TAG + "dispatchTouchEvent()--MotionEvent.ACTION_DOWN");
//                return  false;
                break;
//                return  true;
            case MotionEvent.ACTION_MOVE:
                LogUtils.v(TAG + "dispatchTouchEvent()--MotionEvent.ACTION_MOVE");
//                return  false;
                break;
            case MotionEvent.ACTION_UP:
                LogUtils.v(TAG + "dispatchTouchEvent()--MotionEvent.ACTION_UP");
//                 return false;
                break;
        }
        return super.dispatchTouchEvent(ev);
//        return true;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {

        int e = ev.getAction();
        switch (e) {
            case MotionEvent.ACTION_DOWN:
                LogUtils.v(TAG + "onInterceptTouchEvent()--MotionEvent.ACTION_DOWN");
//                return  false;
                break;
//                return  true;
            case MotionEvent.ACTION_MOVE:
                LogUtils.v(TAG + "onInterceptTouchEvent()--MotionEvent.ACTION_MOVE");
//                return  false;
                break;
            case MotionEvent.ACTION_UP:
                LogUtils.v(TAG + "onInterceptTouchEvent()--MotionEvent.ACTION_UP");
//                  getChildAt(0).dispatchTouchEvent(ev);
//                return false;
                break;
        }
        return super.onInterceptTouchEvent(ev);
//        return true;
    }

    @Override
    public void requestDisallowInterceptTouchEvent(boolean disallowIntercept){
        LogUtils.v(TAG+"requestDisallowInterceptTouchEvent()");

        super.requestDisallowInterceptTouchEvent(disallowIntercept);
    }


}
